﻿/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
**/

package com.chasekernan.hxnova.componenteditor.details;

import com.chasekernan.hxnova.componenteditor.ComponentEditorPanel;
import com.chasekernan.hxnova.componenteditor.DetailsPanel;
import com.chasekernan.hxnova.core.components.Defense;
import org.aswing.JAdjuster;

class DefensePanel extends DetailsPanel {
    
    private var coverageInput : JAdjuster;
    
    public function new() {
        super();
        
        coverageInput = DetailsPanel.createIntAdjuster(0, 9999); //really a float value
        
        addRowHaxe(createLeftLabel("Coverage Per Defense"), coverageInput, createLeftLabel("/ 10000"));
        
        allInputs = [coverageInput];
    }
    
    public override function loadFromComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var defense = cast(ComponentEditorPanel.INSTANCE.editedComponent, Defense);
        
        coverageInput.setValue(Math.round(defense.coverage * 10000.0));
    }
    
    public override function saveToComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var defense = cast(ComponentEditorPanel.INSTANCE.editedComponent, Defense);
        
        defense.coverage = coverageInput.getValue() / 10000.0;
    }
    
}